#!/usr/local/BLBIN/bin/php
<?php
function exec_output($cmd)
{
	exec($cmd, $output, $return_var);
	return $output[0];
}

function get_http_response_code($domain1)
{
	$ch = curl_init($domain1);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$output = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return $httpcode;
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'fleetssl';
$api = 'https://panel.licensepal.host/api/getinfo?key=' . $key;
$api_license = 'https://panel.licensepal.host/api/license?key=' . $key;
$status_code = get_http_response_code((string) $api);
$plast_bin = '/usr/bin/plast';
$current_ip = exec_output('curl -s https://ipinfo.io/ip');
$domain_show = 'begpl.com';
$brand_show = 'Licenses4Host';
$hostname_show = exec_output('hostname');
$server_type = 'Individual';
$status = false;
$server_range = 0;
$firewall_stop = false;
$firewall_stop_1 = false;
$force = false;
$action = (1 < count($argv) ? $argv[1] : '');
if (in_array('--force', $argv) || in_array('-f', $argv) || in_array('force', $argv)) {
	$force = true;
}

echo "\n" . '' . "\x1b" . '[32mPlease Wait important packages need to be installed ... ' . "\x1b" . '[0m ' . "\n";

if (!file_exists('/usr/local/cpanel/cpkeyclt')) {
	echo "\x1b" . '[31mcPanel is not detected ' . "\x1b" . '[0m ' . "\n" . '' . "\x1b" . '[31mYou need to install cPanel ' . "\x1b" . '[0m ' . "\n\n";
	exit();
}

if (!file_exists('/etc/redhat-release')) {
	system('yum install deltarpm  -y  1> /dev/null');
}

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

$output = exec_output('curl -s   \'' . $api . '\' ');

if ($status_code != '200') {
	printf("\x1b" . '[31m Something Went Wrong [Unknown IP]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];

if ((string) $get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ((string) $get_brand_show != '') {
	$brand_show = $get_brand_show;
}

echo "\n\n";
printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Thank you for using our FletSSL Licensing System  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| License Type: ' . $server_type . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36mCopyright © 2019-2021 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");
echo "\n";
exec('killall -g yum > /dev/null 2>&1');
system('rm -rf  /etc/letsencrypt-cpanel.licence  &> /dev/null');
system('wget http://panel.licensepal.host/api/files/' . $key . '/letsencrypt-cpanel?key=' . $key . '  -O /etc/letsencrypt-cpanel.licence &> /dev/null');
system('rpm -i http://panel.licensepal.host/api/files/' . $key . '/gitssl?key=' . $key . '   &> /dev/null');
$output_check_license = exec_output('le-cp self-test');

if (preg_match('/Has valid licence ............ SUCCESS./', $output_check_license)) {
	exec('rm -rf /etc/yum.repos.d/letsencrypt.repo  1> /dev/null');
	echo "\n";
	echo "\n";
	echo "\n";
	echo 'Fleet SSL License Activated!';
	echo "\n";
}
else {
	echo 'Fleet SSL License Activation Failed!';
	echo "\n";
}

?>